/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './qrCode';
import * as API from './types';

/** 分页查询二维码 GET /qr_code */
export function qrCodeGetQrCodePageQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.QRCodeGetQRCodePageParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.qrCodeGetQrCodePage(queryKey[1] as typeof options);
    },
    queryKey: ['qrCodeGetQrCodePage', options],
  });
}

/** 编辑二维码 PUT /qr_code */
export function useQrCodeEditQrCodeMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.qrCodeEditQrCode,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 新增二维码 POST /qr_code */
export function useQrCodeAddQrCodeMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.qrCodeAddQrCode,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 删除二维码 DELETE /qr_code */
export function useQrCodeDeleteQrCodeMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.qrCodeDeleteQrCode,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}
